<?php
class ControllerTravelCate extends Controller{
    public function index(){
        $this->document->setTitle($this->config->get('config_title'));
        $this->document->setDescription($this->config->get('config_meta_description'));

        $this->data['heading_title'] = $this->config->get('config_title');
        $LIMIT = 17; //limit number of tour item output
        
        //get deals of deal-du-lich category
        if (isset($this->request->get['deal-du-lich'])) {
            $category_id = 33; //Category ID for tour-du-lich is 33
            $offset = 0;
            //load model
            $this->load->model('catalog/product');
            
            if (isset($this->request->get['page'])) {
    			$page = $this->request->get['page'];
    		} else {
    			$page = 1;
    		}
            $url = '';
            $offset = 0;
            //init pagination class
            $pagination = new Pagination();
            //setup url and pagination offset
            if (isset($this->request->get['page'])) {
    			$url .= '&page=' . $this->request->get['page'];
                $offset = ((int)$page-1)*$LIMIT;
                
    		}
            $total = $this->model_catalog_product->get_total_product_by_categroryID($category_id);
    		$pagination->total = $total;
    		$pagination->page = $page;
    		$pagination->limit = $LIMIT;
    		$pagination->text = $this->language->get('text_pagination');
    		$pagination->url = $this->url->link('travel/cate&deal-du-lich', '&page={page}', '');
            $cateProducts = $this->model_catalog_product->get_product_by_categroryID($category_id, $offset, $LIMIT);
            
            $this->data['dataModel'] = $cateProducts;
            $this->data['pagination'] = $pagination->render();
            $this->data['total'] = $total;
            //load template
            $this->template = 'default/template/travel/tour.tpl';
        }
        //get deals of deal-khach-san category
        else if(isset($this->request->get['deal-khach-san']))
        {
            $category_id = 25; //Category ID for deal-khach-san is 25
            $offset = 0;
            //load model
            $this->load->model('catalog/product');
            
            if (isset($this->request->get['page'])) {
    			$page = $this->request->get['page'];
    		} else {
    			$page = 1;
    		}
            $url = '';
            $offset = 0;
            //init pagination class
            $pagination = new Pagination();
            //setup url and pagination offset
            if (isset($this->request->get['page'])) {
    			$url .= '&page=' . $this->request->get['page'];
                $offset = ((int)$page-1)*$LIMIT;
                
    		}
            $total = $this->model_catalog_product->get_total_product_by_categroryID(25);
    		$pagination->total = $total;
    		$pagination->page = $page;
    		$pagination->limit = $LIMIT;
    		$pagination->text = $this->language->get('text_pagination');
    		$pagination->url = $this->url->link('travel/cate&deal-khach-san', '&page={page}', '');
            $cateProducts = $this->model_catalog_product->get_product_by_categroryID($category_id, $offset, $LIMIT);
            
            $this->data['dataModel'] = $cateProducts;
            $this->data['pagination'] = $pagination->render();
            $this->data['total'] = $total;
            //load template
            $this->template = 'default/template/travel/hotel.tpl';
        }
        //get hot deals 
        else if(isset($this->request->get['deal-hot']))
        {
            //set type for model call
            $typeRequest = 'special';
            //load model
            $this->load->model('catalog/product');
            
            if (isset($this->request->get['page'])) {
    			$page = $this->request->get['page'];
    		} else {
    			$page = 1;
    		}
    
    		$url = '';
            $offset = 0;
            //init pagination class
            $pagination = new Pagination();
            //setup url and pagination offset
            if (isset($this->request->get['page'])) {
    			$url .= '&page=' . $this->request->get['page'];
                $offset = ((int)$page-1)*$LIMIT;
                
    		}
            
            $total = $this->model_catalog_product->get_total_all_product();
            
    		$pagination->total = $total;
    		$pagination->page = $page;
    		$pagination->limit = $LIMIT;
    		$pagination->text = $this->language->get('text_pagination');
    		$pagination->url = $this->url->link('travel/cate&deal-hot', '&page={page}', '');
            
    		//get necessary paginated tour items 
            $dataModel = $this->model_catalog_product->getNewProductListReceive($typeRequest, $offset, $LIMIT);
            $this->data['dataModel'] = $dataModel;
            $this->data['pagination'] = $pagination->render();
            $this->data['total'] = $total;
            //load template
            $this->template = $this->template = 'default/template/travel/dealhot.tpl';
        }
        //get new received deals
        else if(isset($this->request->get['deal-moi-nhan']))
        {
            //set type for model call
            $typeRequest = 'newReceived';
            //load model
            $this->load->model('catalog/product');
            
            if (isset($this->request->get['page'])) {
    			$page = $this->request->get['page'];
    		} else {
    			$page = 1;
    		}
    
    		$url = '';
            $offset = 0;
            //init pagination class
            $pagination = new Pagination();
            //setup url and pagination offset
            if (isset($this->request->get['page'])) {
    			$url .= '&page=' . $this->request->get['page'];
                $offset = ((int)$page-1)*$LIMIT;
                
    		}
            
            $total = $this->model_catalog_product->get_total_all_product();
            
    		$pagination->total = $total;
    		$pagination->page = $page;
    		$pagination->limit = $LIMIT;
    		$pagination->text = $this->language->get('text_pagination');
    		$pagination->url = $this->url->link('travel/cate&deal-moi-nhan', '&page={page}', '');
            
    		//get necessary paginated tour items 
            $dataModel = $this->model_catalog_product->getNewProductListReceive($typeRequest, $offset, $LIMIT);
            $this->data['dataModel'] = $dataModel;
            $this->data['pagination'] = $pagination->render();
            $this->data['total'] = $total;
            //load template
            
            $this->template = $this->template = 'default/template/travel/dealnew.tpl';
        }
        else
        {
            $this->template = 'default/template/common/home.tpl';
        }
        

        $this->children = array(
            'common/header',
            'common/search',
            'common/footer',
        );

        $this->data['redirectUrl'] = $this->url->link('travel/cate');
        $this->response->setOutput($this->render());
    }
}
?>